package com.ug1yk.dy_download_utils;

import android.Manifest;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothManager;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Environment;
import android.provider.Settings;
import android.util.Log;
import android.util.Pair;


import androidx.annotation.NonNull;
import androidx.lifecycle.Observer;

import java.util.ArrayList;
import java.util.Date;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import kotlinx.coroutines.channels.ChannelResult;

public class BtChannel implements  MethodChannel.MethodCallHandler{
    private static final String TAG = BtChannel.class.getSimpleName();

    private String btChannelName = "com.ug1yk.dy_download";

    private MethodChannel channel;

    public static final String MESSAGE_SEND_DY_URL="MESSAGE_SEND_DY_URL";

    public BtChannel(BinaryMessenger binaryMessenger, Context mContext) {
        channel = new MethodChannel(binaryMessenger, btChannelName);
        channel.setMethodCallHandler(this);

        ShareInstance.instance.getUrlLive().observeForever(new Observer<String>() {
            @Override
            public void onChanged(String dyUrl) {
                sendShareUrl(dyUrl);
            }
        });
    }

    @Override
    public void onMethodCall(@NonNull MethodCall methodCall, @NonNull MethodChannel.Result result) {
        if (methodCall == null || result == null) {
            return;
        }

    }

    /**
     * 发送分享的抖音链接
     *
     * @param dyUrl
     */
    private void sendShareUrl(String dyUrl) {
        Log.d(TAG, "sendShareUrl() called with: dyUrl = [" + dyUrl + "]");
        channel.invokeMethod(MESSAGE_SEND_DY_URL, dyUrl);
    }

}
